//
//  TitleTableViewContrller.m
//  HouseShow
//
//  Created by gongjie on 11-12-26.
//  Copyright (c) 2011年 __MyCompanyName__. All rights reserved.
//

#import "TitleTableViewContrller.h"


@implementation TitleTableViewContrller

@synthesize delegate;
@synthesize Listdate;
- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
        Listdate = [[NSMutableArray alloc] init];
//        [self.tableView setDelegate:self];
//        [self.tableView setDataSource:self];
       
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
//    UIImageView* tImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bar2.png"]];
    
    UIButton* leftBt = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBt.tag =1;
    leftBt.frame =CGRectMake(10, 8, 40, 30);
    [leftBt setImage:[UIImage imageNamed:@"bar2.png"] forState:UIControlStateNormal];
    [leftBt addTarget:self action:@selector(changelistleft) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton* rightBt = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBt.tag =2;
    rightBt.frame =CGRectMake(270, 8, 40, 30);
    [rightBt setImage:[UIImage imageNamed:@"bar1.png"] forState:UIControlStateNormal];
    [rightBt addTarget:self action:@selector(changelistright) forControlEvents:UIControlEventTouchUpInside];
    
    [self.navigationController.navigationBar addSubview:leftBt];
    [self.navigationController.navigationBar addSubview:rightBt];
    
//    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"bar2.png"] style:100 target:self action:@selector(changelistleft)];
//    [[UIBarButtonItem alloc] initWithCustomView:tImgView];
//    self.navigationItem.leftBarButtonItem.target = self;
//    self.navigationItem.leftBarButtonItem.action =@selector(changelistleft);
//    [tImgView  release];
//    tImgView = nil;
//    self.navigationItem.leftBarButtonItem.tag = 1;
    
   
//    tImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bar1.png"]];
//    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"bar1.png"] style:100 target:self action:@selector(changelistright)];
//    [[UIBarButtonItem alloc] initWithCustomView:tImgView];
//    self.navigationItem.rightBarButtonItem.target = self;
//    self.navigationItem.rightBarButtonItem.action =@selector(changelistright);
//    self.navigationItem.leftBarButtonItem.tag = 2;

   }
-(void)changelistleft
{
    if (delegate !=nil&& [delegate conformsToProtocol:@protocol(TitleTableVieDelegate)]) {
        if([delegate respondsToSelector:@selector(SendPreviousPage)]) {
            [delegate SendPreviousPage];
        }
    }
}
-(void)changelistright{
    if (delegate !=nil&& [delegate conformsToProtocol:@protocol(TitleTableVieDelegate)]) {
        if([delegate respondsToSelector:@selector(SendNextPage)]) {
            [delegate SendNextPage];
        }
    }
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

//- (void)viewWillAppear:(BOOL)animated
//{
//    [super viewWillAppear:animated];
//}
//
//- (void)viewDidAppear:(BOOL)animated
//{
//    [super viewDidAppear:animated];
//}
//
//- (void)viewWillDisappear:(BOOL)animated
//{
//    [super viewWillDisappear:animated];
//}
//
//- (void)viewDidDisappear:(BOOL)animated
//{
//    [super viewDidDisappear:animated];
//}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return YES;
}

#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [Listdate count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
        [cell.imageView setImage:[UIImage imageNamed:@"biandian"]];
        UILabel* toptil = [[UILabel alloc] initWithFrame:CGRectMake(40, 5, cell.frame.size.width-100, 20)];
        toptil.tag = 100;
        [toptil setBackgroundColor:[UIColor clearColor]];
        toptil.font = [UIFont systemFontOfSize:18];
        toptil.textColor = [UIColor blackColor];
        [cell.contentView addSubview:toptil];
        [toptil release];
        UILabel* time = [[UILabel alloc] initWithFrame:CGRectMake(40, 35, cell.frame.size.width-100, 20)];
        time.tag = 101;
        [time setBackgroundColor:[UIColor clearColor]];
        time.font = [UIFont systemFontOfSize:18];

        time.textColor = [UIColor blackColor];
        [cell.contentView addSubview:time];
        [time release];
    }
    if ([Listdate count]>0) {
        NSDictionary* data= (NSDictionary*)[Listdate objectAtIndex:[indexPath row]];

        UILabel* zheng =(UILabel*)[cell viewWithTag:100];
        zheng.text = (NSString*)[data objectForKey:@"title"];
        zheng = nil;
        UILabel* zheng1 =(UILabel*)[cell viewWithTag:101];
        zheng1.text = (NSString*)[data objectForKey:@"ptime"];
        zheng1 = nil;
    }


    return cell;
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
     [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSUInteger row = [indexPath row];
    if (delegate !=nil&& [delegate conformsToProtocol:@protocol(TitleTableVieDelegate)]) {
        if([delegate respondsToSelector:@selector(getindex:)]) {
            [delegate getindex:row];
        }
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}
-(void)dealloc
{    
    [Listdate release];
    delegate = nil;
    [super dealloc];
}

@end
